describe('Unit Directives', function () {
    var ele, scope, directiveScope, controller;
    beforeEach(module('testProject'));
    beforeEach(module('templates'));
    beforeEach(inject(function ($compile, $rootScope) {
        scope = $rootScope.$new();
        ele = angular.element(
            '<employee-list employees="employeeList"></employee-list>'
        );
        scope.employeeList = [
            { id: 1, name: 'Adam',age:'40', phone: '192-1345-2987', position: 'manager' },
            { id: 2, name: 'Bob',age:'32', phone: '192-5726-4582', position: 'engineer' },
            { id: 3, name: 'Cate',age:'26', phone: '192-3546-2837', position: 'engineer' }
        ];
        $compile(ele)(scope);
        scope.$digest(ele);
        directiveScope = ele.isolateScope();
    }))

    it("should display the employees'names", function () {
        var items = ele.find('.item');
        expect(
            items.length
        ).toBe(3);
        expect(
            items.eq(0).text()
        ).toContain('Adam')
        expect(
            items.eq(1).text()
        ).toContain('Bob')
    })

    it("should open only one employ's bio content", function () {
        var items = ele.find('.name');

        items.eq(1).click();

        expect(
            directiveScope.activeIndex
        ).toBe(1);

        var content = ele.find('.content');

        expect(
            content.text()
        ).toContain('192-5726-4582')

        items.eq(2).click();

        expect(
            directiveScope.activeIndex
        ).toBe(2);

        var content = ele.find('.content');

        expect(
            content.text()
        ).not.toContain('192-5726-4582')

        expect(
            content.text()
        ).toContain('192-3546-2837')
    })

    it("should show an alert when click then content", function () {
        var items = ele.find('.name');

        items.eq(1).click();

        var content = ele.find('.content');

        spyOn(window, 'alert');
        content.eq(0).click();
        expect(
            window.alert
        ).toHaveBeenCalledWith('Should call Bob with 192-5726-4582');
    })
})